package com.hp.attendance.service;

import com.hp.attendance.dao.PositionDao;
import com.hp.attendance.dao.PositionDao;
import com.hp.attendance.entity.Position;
import com.hp.attendance.entity.PageInfo;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

public class PositionService {
    private PositionDao positionDao = new PositionDao();

    public PageInfo<Position> getPositionList(int pageNo , int pageSize) throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        PageInfo<Position> page = new PageInfo<Position>();
        //查询分页的数据                           2       10
        List<Position> list = positionDao.getPositionList(pageNo, pageSize);

        page.setRecords(list);
        //查询总记录条数
        long total = positionDao.getTotal();
        page.setTotal(total);
        //设置当前页码
        page.setCurrent(pageNo);
        //设置总页数
        int pages = (int)Math.ceil(total / (pageSize * 1.0));
        page.setPages(pages);
        return page;
    }

    public void PositionAdd(Position position) throws SQLException, IOException, ClassNotFoundException {
        positionDao.PositionAdd(position);
    }

    public Position getPositionMAX() throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        return positionDao.getPositionMAX();
    }
    public void PositionDel(int id) throws SQLException, IOException, ClassNotFoundException {
        positionDao.PositionDel(id);
    }
    public void PositionUpdate(Position position) throws SQLException, IOException, ClassNotFoundException {
        positionDao.PositionUpdate(position);
    }
    public Position positionPreUpd(int id) throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        return positionDao.positionPreUpd(id);
    }

    public List<Position> getList() throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        return positionDao.getList();
    }
}
